<script type='text/javascript' src='{theme:javascript/artTemplate/area_select.js}'></script>

<article class="module width_full">
	<header>
		<h3 class="tabs_involved">订单发货</h3>
	</header>

	<form action="{url:/seller/order_delivery_doc}" method="post" id="deliver_form">
		<input type="hidden" name="order_no" value="{$order_no}"/>
		<input type="hidden" name="id" value="{$order_id}"/>
		<input type="hidden" name="weight_total" id="weight_total" value="{$goods_weight}"/>
		<input type="hidden" name="user_id" value="{$user_id}"/>
		<input type="hidden" name="freight" value="{$real_freight}" />

		<fieldset>
			<table class="tablesorter clear">
				<thead>
					<tr>
						<th>商品名称</th>
						<th>商品价格</th>
						<th>购买数量</th>
						<th onclick="selectAll('sendgoods[]')">选择发货</th>
					</tr>
				</thead>

				<tbody>
					{set:$seller_id = $this->seller['seller_id']}
					{query:name=order_goods as og join=left join goods as go on go.id eq og.goods_id fields=og.*,go.seller_id where=og.order_id eq $order_id and go.seller_id eq $seller_id}
					<tr>
						<td>
							{set:$goodsRow = JSON::decode($item['goods_array'])}
							{$goodsRow['name']} &nbsp;&nbsp; {$goodsRow['value']}
						</td>
						<td>{$item['real_price']}</td>
						<td>{$item['goods_nums']}</td>
						<td>
							{if:$item['is_send'] == 0}
							<input type="checkbox" name="sendgoods[]" value="{$item['id']}" />
							{else:}
							{echo:Order_class::goodsSendStatus($item['is_send'])}
							{/if}
						</td>
					</tr>
					{/query}
				</tbody>
			</table>
		</fieldset>

		<fieldset>
			<table class="tablesorter clear">
				<colgroup>
					<col width="120px" />
					<col />
					<col width="120px" />
					<col />
				</colgroup>

				<tbody>
					<tr>
						<th>订单号:</th><td align="left">{$order_no}</td>
						<th>下单时间:</th><td align="left">{$create_time}</td>
					</tr>
					<tr>
						<th>配送方式:</th>
						<td align="left">
							<select name="delivery_type" pattern="required" alt="请选择配送方式" class="auto" disabled="disabled">
							{query:name=delivery where=is_delete eq 0}
							<option value="{$item['id']}" {if:$distribution==$item['id']}selected{/if}>{$item['name']}</option>
							{/query}
							</select>
						</td>
						<th>配送费用:</th><td align="left">{$real_freight}</td>
					</tr>
					<tr>
						<th>是否保价:</th><td align="left">{if:$if_insured==0}否{else:}是{/if}</td><th>保价费用:</th><td align="left">￥{$insured}</td>
					</tr>
					<tr>
						<th>收货人姓名:</th><td align="left"><input type="text" class="small" name="name" value="{$accept_name}" pattern="required"/></td>
						<th>电话:</th><td align="left"><input type="text" class="small" name="telphone" value="{$telphone}" pattern="phone" empty /></td>
					</tr>
					<tr>
						<th>手机:</th><td align="left"><input type="text" class="small" name="mobile" value="{$mobile}" pattern="mobi"/></td>
						<th>邮政编码:</th><td align="left"><input type="text" name="postcode" class="small" value="{$postcode}" pattern="zip" empty /></td>
					</tr>
					<tr>
						<th>物流公司：</th>
						<td align="left">
							<select name="freight_id" pattern="required">
								{query:name=freight_company where=is_del eq 0}
								<option value="{$item['id']}">{$item['freight_name']}</option>
								{/query}
							</select>
						</td>
						<th>配送单号:</th><td align="left"><input type="text" class="normal" name="delivery_code" pattern="required"/></td>
					</tr>
					<tr>
						<th>地区:</th>
						<td align="left" colspan="3">
							<select name="province" child="city,area" onchange="areaChangeCallback(this);" class="auto"></select>
							<select name="city" child="area" parent="province" onchange="areaChangeCallback(this);" class="auto"></select>
							<select name="area" parent="city" pattern="required" class="auto"></select>
						</td>
					</tr>
					<tr>
						<th>地址:</th><td align="left" colspan="3"><input type="text" class="normal" name="address" value="{$address}" size="50" pattern="required"/></td>
					</tr>
					<tr>
						<th>发货单备注:</th><td align="left" colspan="3"><textarea name="note" class="normal"></textarea></td>
					</tr>
				</tbody>
			</table>
		</fieldset>

		<footer>
			<div class="submit_link">
				<input type="submit" class="alt_btn" value="确 定" onclick="return checkForm()" />
				<input type="reset" value="重 置" />
			</div>
		</footer>
	</form>
</article>

<script type="text/javascript">
//DOM加载完毕
$(function(){
	//初始化地域联动
	template.compile("areaTemplate",areaTemplate);

	createAreaSelect('province',0,{$province});
	createAreaSelect('city',{$province},{$city});
	createAreaSelect('area',{$city},{$area});
});

/**
 * 生成地域js联动下拉框
 * @param name
 * @param parent_id
 * @param select_id
 */
function createAreaSelect(name,parent_id,select_id)
{
	//生成地区
	$.getJSON("{url:/block/area_child}",{"aid":parent_id,"random":Math.random()},function(json)
	{
		$('[name="'+name+'"]').html(template.render('areaTemplate',{"select_id":select_id,"data":json}));
	});
}

//表单提交前检测
function checkForm()
{
	var checkedNum = $('input[name="sendgoods[]"]:checked').length;
	if(checkedNum == 0)
	{
		alert('请选择要发货的商品');
		return false;
	}
	return true;
}
</script>